package main

import (
	"dc-news/common/global/setting"
	"dc-news/common/log"
	"dc-news/common/utils/redis"
	"dc-news/common/utils/upyun"
	"dc-news/dao/db"
	"dc-news/dao/mongo"
	"dc-news/routers"
	"fmt"
	"go.uber.org/zap"
)

func main() {
	log.InitLogs(zap.DebugLevel, "./logs/dc-news.log")
	if err := setting.Init("./conf/config.ini"); err != nil {
		zap.L().Error(err.Error())
		return
	}
	if err := db.InitMySQL(); err != nil {
		zap.L().Error(err.Error())
		return
	}
	if err := redis.InitRedis(); err != nil {
		zap.L().Error(err.Error())
		return
	}
	if err := upyun.InitUpYun(); err != nil {
		zap.L().Error(err.Error())
		return
	}
	if err := mongo.InitMongoDB(); err != nil {
		zap.L().Error(err.Error())
		return
	}
	r := routers.SetupRouter()
	if err := r.Run(fmt.Sprintf(":%d", setting.Conf.Port)); err != nil {
		zap.L().Error(err.Error())
		return
	}
}
